$(window).load(function(){
    
    // ieCheck
    var ie = false;
    var aniButtonDuration = 350;
    
    if($.browser.msie && $.browser.version<9)
    {
        aniButtonDuration = 0;
        ie = true;
    }
    
    
    //resize
   	var mainDIV = $('.main');
    
    var minW = $('body').css("min-width");
    var minH = $('body').css("min-height");
    
    
    mainDIV_H = 628;
    
    var window_W = $(document).width();
    var window_H = $(document).height();

    $(window).resize(function()
    {
       resizeContent(500);
    });
    
    
    function resizeContent(_animationSpeed)
    {
        window_W = $(document).width();
        window_H = $(document).height();
        
        if (window_H - 270 > mainDIV_H) {
			mainDIV.stop().animate({marginTop:~~((window_H -270 - mainDIV_H)/2)}, _animationSpeed, 'easeOutCubic');	
		} else {
			mainDIV.stop().animate({marginTop:0}, _animationSpeed, 'easeOutCubic');	
		}	
    }
    
    
     
    $('#bgStretch')
	  .bgStretch({
		navigs:$('#bgNav').navigs()
	}).sImg({
		spinner:$('.gall_spinner').hide()
	})
    

    
    $('#bgNav li > a').hover(function()
    {
        if(!$(this).parent().hasClass('active')){
            $(this).find('span').stop().animate({opacity:1}, aniButtonDuration,'easeOutCubic')
            $(this).find('div').stop().animate({opacity:0}, aniButtonDuration,'easeOutCubic')
        }					   
    }, function(){
        if(!$(this).parent().hasClass('active')){
    	    $(this).find('span').stop().animate({opacity:0}, aniButtonDuration,'easeOutCubic')
    	    $(this).find('div').stop().animate({opacity:1}, aniButtonDuration,'easeOutCubic')
        }						   
    })
    
    $('#content > ul > li > div > a')
	.sprites({
		method:'simple',
		duration:400,
		easing:'easeOutQuint',
		hover:true
	})
    
    resizeContent(0);

    /////////////////////////////////////////////////////////////////////////// 
    //                           content switch                              //
    ///////////////////////////////////////////////////////////////////////////
    
    var content=$('#content'),
        nav=$('.menu'),
        logoPlane = $('#logo > span'),
        logoHolder = $('#logoHolder');
    
    
    $('#menu').superfish({
      delay:       700,
      animation:   {height:'show'},
      speed:       350,
      autoArrows:  false,
      dropShadows: false
    });
     

    nav.navs({
		useHash:true,
        defHash:'#!/',
		hoverIn:function(li){
 	          $('>a',li).stop().animate({color:'#717171'}, 250,'easeOutSine');
		},
		hoverOut:function(li){
		  if (!li.hasClass('with_ul') || !li.hasClass('sfHover')) {
              $('>a',li).stop().animate({color:'#fff'}, 250,'easeOutSine');  
          }
		}				
    })
    
     content.tabs({
		preFu:function(_)
        {
            _.li.css({display:'none', top:'223px', height:'0px'});
		}
		,actFu:function(_)
        {
            
            if(_.pren == undefined){
                aniDelay = 0;
            } else {
                aniDelay = 400;
            }
            
            if(_.n == -1){
                logoHolder.stop().delay(aniDelay-100).animate({top:'195px'}, 550,'easeOutQuint')
                logoPlane.delay(aniDelay-100).fadeIn(450);
            } else {
                logoHolder.stop().animate({top:'-70px'}, 650,'easeOutQuint')
                logoPlane.fadeOut(550);
            }
            
        	if(_.curr){
				_.curr
					.stop()
					.delay(aniDelay).css({display:'block', height:'0px'}).animate({top:'0px', height:'446px'}, 650,'easeOutCubic');
            }

			if(_.prev){
			    _.prev 
    				.stop()
    				.animate({top:'223px', height:'0px'}, 350,'easeInSine', function(){
    				     $(this).css({display:'none'});
    			     });
            }
           
        }
		
	})
       
    nav.navs(function(n, _)
    {
		content.tabs(n);
	})
    
 
})